package com.temi.iot.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.temi.iot.common.constant.factory.PageFactory;
import com.temi.iot.common.constant.result.Page;
import com.temi.iot.common.constant.result.Result;
import com.temi.iot.entity.SysRole;
import com.temi.iot.enums.DeleteEnum;
import com.temi.iot.service.ISysRoleService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author one
 * @since 2019-12-11
 */
@Service
public class SysRoleServiceImpl implements ISysRoleService {

    @Override
    public Result insertRole(SysRole sysRole) {
        sysRole.insert();
        return Result.SUCCESS;
    }

    @Override
    public Result updateRole(SysRole sysRole) {
        sysRole.updateById();
        return Result.SUCCESS;
    }

    @Override
    public Result deleteRole(Long id) {
        SysRole.builder().id(id).deleteType(DeleteEnum.DELETE.type)
                .build().updateById();
        return Result.SUCCESS;
    }

    @Override
    public Result selectRoleDetail(Long id) {
        SysRole sysRole = SysRole.builder().build().selectById(id);
        return Result.success(sysRole);
    }

    @Override
    public Page selectRoleList() {
        return PageFactory.page(()->SysRole.builder().build()
                .selectList(new EntityWrapper().eq("delete_type",DeleteEnum.DELETE.type)));
    }
}
